require "Fake UI, KR and HP"
require "Papyrus Animation"

music = "nothing"
arenasize = {155,130}
wavetimer = 1/0
encountertext = ""

flee = true
fleesuccess = false
playerskipdocommand = true
unescape = true
progress = 0
phase = 1
Volumen = 1
timer = -1
Alternative = 0
Salir = 0
FUN = {"None", 0}

if not GetAlMightyGlobal("Seconds") then
	SetAlMightyGlobal("Seconds", 0)
end
if not GetAlMightyGlobal("Minutes") then
	SetAlMightyGlobal("Minutes", 0)
end
if not GetAlMightyGlobal("Hours") then
	SetAlMightyGlobal("Hours", 0)
end

enemies = {
"Disbelief Papyrus",
"Disbelief Sans",
"Disbelief Undyne",
"Egg Dog"
}

enemypositions = {
{0, 10},
{90, 10},
{0, 10},
{0, -10}
}

phase1 = {"Attack 1", "Attack 2", "Attack 3", "Attack 4", "Attack 5", "Attack 6", "Spare"}
phase2 = {"Intro Phase 2", "Attack 7", "Free Space", "Attack 9"}
phase3 = {"Attack 10", "Attack 11", "Attack 12"}
StatusPhase3 = {"", "", ""}

function EncounterStarting()
	Misc.WindowName = "Disbelief Papyrus"
	if not GetAlMightyGlobal("Idioma") then
		SetAlMightyGlobal("Idioma", "English")
	end
	if not GetAlMightyGlobal("Archivimentazo") then
		SetAlMightyGlobal("Archivimentazo", "00000000000000000000000000")
	end
	if not GetAlMightyGlobal("ProgresoProgresivamenteProgresante1") then
		SetAlMightyGlobal("ProgresoProgresivamenteProgresante1", "000000")
	end
	if not GetAlMightyGlobal("ProgresoProgresivamenteProgresante2") then
		SetAlMightyGlobal("ProgresoProgresivamenteProgresante2", "0000000")
	end
	enemies[1].Call("SetBubbleOffset", {-10, 90})
	Player.name = "Chara"
	Player.lv = 19
	Player.hp = 92
	ConfigurateKR(true, false)
	Player.SetAttackAnim({"UI/Battle/spr_slice_o_0","UI/Battle/spr_slice_o_1","UI/Battle/spr_slice_o_2","UI/Battle/spr_slice_o_3","UI/Battle/spr_slice_o_4","UI/Battle/spr_slice_o_5"}, 0.1)
	LoadMusic()
	LoadSounds()
	GameMusic = "None"
	Inventory.AddCustomItems({"Pie", "Pay", "SnowPiece", "P. Nieve", "L. Hero", "Héroe L.", "Spaghetti", "Espagueti", "C. Spaghetti", "Espagueti F.", "[starcolor:7d7d7d][color:7d7d7d]Nothing[color:ffffff]", "[starcolor:7d7d7d][color:7d7d7d]Nada[color:ffffff]"},{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 3})
	AbsBlack1 = CreateSprite("Pixel", "Top")
	AbsBlack2 = CreateSprite("Pixel", "Top")
	AbsBlack1.color = {0,0,0}
	AbsBlack2.color = {0,0,0}
	AbsBlack1.Scale(1000, 480)
	AbsBlack2.Scale(1000, 480)
	AbsBlack1.MoveTo(-500, 240)
	AbsBlack2.MoveTo(1140, 240)
	nextwaves = {"Loader"}
	State("DEFENDING")
end

function Update()
	if StartCounting then
		if StartCounting + tiempo <= Time.time and not GetAlMightyGlobal("MaxTime") then
			tiempo = tiempo + 1
			SetAlMightyGlobal("Seconds", GetAlMightyGlobal("Seconds") + 1)
			if GetAlMightyGlobal("Seconds") >= 60 then
				SetAlMightyGlobal("Minutes", GetAlMightyGlobal("Minutes") + 1)
				SetAlMightyGlobal("Seconds", GetAlMightyGlobal("Seconds") - 60)
			end
			if GetAlMightyGlobal("Minutes") >= 60 then
				SetAlMightyGlobal("Hours", GetAlMightyGlobal("Hours") + 1)
				SetAlMightyGlobal("Minutes", GetAlMightyGlobal("Minutes") - 60)
			end
			if GetAlMightyGlobal("Hours") == 9 and GetAlMightyGlobal("Minutes") == 59 and GetAlMightyGlobal("Seconds") == 59 then
				SetAlMightyGlobal("MaxTime", true)
			end
		end
	end
	if not StopEncounter then
		AnimatePapyrus()
		UpdateUI()
		if Input.GetKey("H") == 1 then
			State("ACTIONSELECT")
			nextwaves = {"No Bitch NO!"}
			State("DEFENDING")
		end
		if timer >= 0 then
			timer = timer + 1
			if timer == 31 then
				Bone = CreateSprite("Bullets/Bones/BoneP", "BelowBullet")
				Bone.MoveTo(48, -6)
				Bone.rotation = 90
			elseif timer > 31 then
				Bone.MoveTo(48, -6 + 40*math.abs(math.sin(math.rad(180/40*(timer - 31)))))
				if timer%40 == 31 and (Bad or Done) then
					Bone.Remove()
					Bone = nil
					timer = -1
				end
			end
			if Bone and Bone.y >= Player.absy - 8 and Player.absx <= 87 then
				if FUN[1] == "Legendary" and FUN[2] == 3 then
					X = Player.absx
					Y = Player.absy
					nextwaves = {"SIKE!"}
					FUN = {"None", 0}
					Player.hp = 1
					State("DEFENDING")
				else
					if Player.hp > 20 then
						Player.Hurt(20)
					elseif Player.hp > 1 then
						Player.Hurt(Player.hp - 1)
					end
				end
			end
		end
		if phase == -1 then
			if GameMusic == "ShortIntro" then
				NewAudio.PlaySound("One", "Intro Phase 1 Short", false, 1)
				NewAudio.SetPlayTime("One", 0)
				GameMusic = "Slow"
			elseif GameMusic == "Slow" and NewAudio.GetPlayTime("One") > 0.9 then
				if Volumen > 0 then
					Volumen = Volumen - 0.004
				end
				NewAudio.SetPitch("One", Volumen)
				if Volumen <= 0 then
					NewAudio.Stop("One")
					NewAudio.SetPitch("One", 1)
					GameMusic = "None"
					Volumen = 1
				end
			end
		elseif phase == 1 then
			if GameMusic == "StartImmediate" then
				NewAudio.PlaySound("One", "Intro Phase 1", false, 1)
				NewAudio.SetPlayTime("One", 22.645)
				GameMusic = "Intro"
			elseif GameMusic == "Start" then
				NewAudio.PlaySound("One", "Intro Phase 1", false, 1)
				GameMusic = "Intro"
			elseif GameMusic == "Intro" and (NewAudio.GetPlayTime("One") > 78.28 or NewAudio.isStopped("One")) then
				NewAudio.PlaySound("Loop", "Loop Phase 1", true, 1)
				GameMusic = "Playing"
			elseif GameMusic == "Volume" then
				if Volumen > 0.2 then
					Volumen = Volumen - 0.01
				end
				NewAudio.SetVolume("Loop", Volumen)
			elseif GameMusic == "Cry" then
				NewAudio.SetVolume("Loop", 0)
				NewAudio.Stop("Loop")
				NewAudio.PlaySound("One", "Ending Phase 1", false, Volumen)
				GameMusic = "Crying"
			elseif GameMusic == "Crying" then
				if Volumen < 1 then
					Volumen = Volumen + 0.01
				end
				NewAudio.SetVolume("One", Volumen)
			elseif GameMusic == "Believe" then
				NewAudio.PlaySound("Loop", "Believe", true, 1)
				GameMusic = "Wait"
			elseif GameMusic == "Stop" then
				NewAudio.SetPitch("Loop", 1)
				NewAudio.SetVolume("Loop", 0)
				NewAudio.Stop("Loop")
				Volumen = 1
				GameMusic = "End"
				phase = 2
				progress = 0
			elseif GameMusic == "NYEH!" then
				Volumen = Volumen - 0.01
				if NewAudio.GetVolume("One") > Volumen then
					NewAudio.SetVolume("One", Volumen)
				end
				if NewAudio.GetVolume("Loop") > Volumen then
					NewAudio.SetVolume("Loop", Volumen)
				end
				if Volumen <= 0 then
					NewAudio.SetVolume("One", 0)
					NewAudio.Stop("One")
					NewAudio.PlaySound("Loop", "Papyrus", true, 1)
					GameMusic = "WOWIE"
				end
			end
		elseif phase == 2 then
			if GameMusic == "Start" then
				NewAudio.PlaySound("One", "Intro Phase 2", false, 1)
				GameMusic = "Intro"
			elseif GameMusic == "Intro" and (NewAudio.GetPlayTime("One") > 13.34 or NewAudio.isStopped("One")) then
				NewAudio.PlaySound("One", "Intro 1 Phase 2", false, 1)
				GameMusic = "Loop 1"
			elseif GameMusic == "Loop 1" and (NewAudio.GetPlayTime("One") > 13.3 or NewAudio.isStopped("One")) then
				NewAudio.PlaySound("Loop", "Loop 1 Phase 2", true, 1)
				GameMusic = "Wait 1"
			elseif GameMusic == "Continue 1" then
				NewAudio.SetVolume("Loop", 0)
				NewAudio.Stop("Loop")
				NewAudio.PlaySound("One", "Intro 2 Phase 2", false, 1)
				GameMusic = "Loop 2"
			elseif GameMusic == "Loop 2" and (NewAudio.GetPlayTime("One") > 13.3 or NewAudio.isStopped("One")) then
				NewAudio.PlaySound("Loop", "Loop 2 Phase 2", true, 1)
				GameMusic = "Wait 2"
			elseif GameMusic == "Continue 2" then
				NewAudio.SetVolume("Loop", 0)
				NewAudio.Stop("Loop")
				NewAudio.PlaySound("One", "Intro 3 Phase 2", false, 1)
				GameMusic = "Loop 3"
			elseif GameMusic == "Loop 3" and (NewAudio.GetPlayTime("One") > 53.84 or NewAudio.isStopped("One")) then
				NewAudio.SetPlayTime("One", 0)
				NewAudio.Stop("One")
				NewAudio.PlaySound("Loop", "Loop 3 Phase 2", true, 1)
				GameMusic = "Wait 3"
			elseif GameMusic == "Continue 3" then
				NewAudio.SetVolume("Loop", 0)
				NewAudio.Stop("Loop")
				NewAudio.PlaySound("One", "Intro 4 Phase 2", false, 1)
				GameMusic = "Wait 4"
			elseif GameMusic == "Continue 4" then
				NewAudio.SetVolume("One", 0)
				NewAudio.Stop("One")
				NewAudio.PlaySound("Loop", "choice", true, 1)
				GameMusic = "Wait 5"
			end
		elseif phase == 3 then
			if GameMusic == "Prepare" then
				NewAudio.SetVolume("Loop", 0)
				NewAudio.Stop("Loop")
				NewAudio.PlaySound("One", "Intro 1 Phase 3", false, 1)
				GameMusic = "Waiting"
			elseif GameMusic == "Waiting" and (NewAudio.GetPlayTime("One") > 25.02 or NewAudio.isStopped("One")) then
				NewAudio.PlaySound("Loop", "Loop 1 Phase 3", true, 1)
				GameMusic = "Wait 1"
			elseif GameMusic == "Continue 1" and ((NewAudio.GetPlayTime("Loop") > 2.37 and NewAudio.GetPlayTime("Loop") <= 2.4) or NewAudio.GetPlayTime("Loop") > 4.77) then
				NewAudio.SetVolume("Loop", 0)
				NewAudio.Stop("Loop")
				NewAudio.PlaySound("One", "Intro 2 Phase 3", false, 1)
				GameMusic = "Loop 1"
			elseif GameMusic == "Loop 1" and (NewAudio.GetPlayTime("One") > 48.24 or NewAudio.isStopped("One")) then
				NewAudio.PlaySound("Loop", "Loop 2 Phase 3", true, 1)
				GameMusic = "Wait 2"
			elseif GameMusic == "Continue 2" and NewAudio.GetPlayTime("Loop") > 9.59 then
				NewAudio.SetVolume("Loop", 0)
				NewAudio.Stop("Loop")
				NewAudio.PlaySound("One", "Intro 3 Phase 3", false, 1)
				GameMusic = "Loop 2"
			elseif GameMusic == "Loop 2" and (NewAudio.GetPlayTime("One") > 30.9 or NewAudio.isStopped("One")) then
				NewAudio.PlaySound("Loop", "Loop 3 Phase 3", true, 1)
				GameMusic = "Wait 3"
			elseif GameMusic == "Continue 3" and NewAudio.GetPlayTime("Loop") > 2.37 then
				NewAudio.SetVolume("Loop", 0)
				NewAudio.Stop("Loop")
				NewAudio.PlaySound("One", "Intro 4 Phase 3", false, 1)
				GameMusic = "Loop 3"
			elseif GameMusic == "Loop 3" and (NewAudio.GetPlayTime("One") > 105.58 or NewAudio.isStopped("One")) then
				NewAudio.PlaySound("Loop", "Loop 4 Phase 3", true, 1)
				GameMusic = "Wait 4"
			elseif GameMusic == "Continue 4" and ((NewAudio.GetPlayTime("Loop") > 4.77 and NewAudio.GetPlayTime("Loop") <= 4.8) or NewAudio.GetPlayTime("Loop") > 9.58) then
				NewAudio.SetVolume("Loop", 0)
				NewAudio.Stop("Loop")
				NewAudio.PlaySound("One", "Intro 5 Phase 3", false, 1)
				GameMusic = "Loop 4"
			elseif GameMusic == "Loop 4" and (NewAudio.GetPlayTime("One") > 0.24 or NewAudio.isStopped("One")) then
				NewAudio.PlaySound("Loop", "Loop 5 Phase 3", true, 1)
				GameMusic = "Wait 5"
			elseif GameMusic == "Continue 5" and NewAudio.GetPlayTime("Loop") > 1.17 then
				NewAudio.SetVolume("Loop", 0)
				NewAudio.Stop("Loop")
				NewAudio.PlaySound("One", "Intro 6 Phase 3", false, 1)
				GameMusic = "End"
			end
		elseif phase == 4 then
			if GameMusic == "Finale" then
				NewAudio.SetVolume("Loop", 0)
				NewAudio.Stop("Loop")
				NewAudio.PlaySound("One", "Phase 4", false, 1)
				GameMusic = "It's Over"
			elseif GameMusic == "NYEH!" then
				NewAudio.SetVolume("One", 0)
				NewAudio.Stop("One")
				NewAudio.PlaySound("Loop", "Papyrus", true, 1)
				GameMusic = "WOWIE"
			end
		end
		if GameMusic == "Fade" then
			Volumen = Volumen - 0.005
			if NewAudio.GetVolume("One") > Volumen then
				NewAudio.SetVolume("One", Volumen)
			end
			if NewAudio.GetVolume("Loop") > Volumen then
				NewAudio.SetVolume("Loop", Volumen)
			end
			if Volumen <= 0 then
				GameMusic = "End"
			end
		end
		if timerMiss then
			timerMiss = timerMiss + 1
			if timerMiss == 90 then
				Miss.Remove()
				Miss = nil
				timerMiss = nil
			end
		end
		if Input.GetKey("Escape") > 0 then
			if not Quitando then
				Quitando = CreateSprite("Quiting1 "..GetAlMightyGlobal("Idioma"),"Top")
				Quitando.MoveTo(90, 460)
				Quitando.color = {0.75, 0.75, 0.75}
			end
			Salir = Salir + 1
		else
			if Quitando then
				Quitando.Remove()
				Quitando = nil
			end
			Salir = 0
		end
		if Quitando then
			Quitando.alpha = 1/120*Salir
			if Salir == 60 then
				Quitando.Set("Quiting2 "..GetAlMightyGlobal("Idioma"))
			elseif Salir == 120 then
				Quitando.Set("Quiting3 "..GetAlMightyGlobal("Idioma"))
			end
			Quitando.SendToTop()
		end
		if Salir == 180 then
			State("DONE")
		end
	end
	AbsBlack1.SendToTop()
	AbsBlack2.SendToTop()
end

function EnteringState(new, old)
	if new == "ATTACKING" then
		if phase == -1 then
			nextwaves = {"Dude NO"}
			State("DEFENDING")
		elseif phase == 4 and (not Scared or Scared <= 4) then
			Animation = "WAIT!"
			vel = 0
		end
	elseif Player.absy < 175 and old == "MERCYMENU" and (new == "ENEMYDIALOGUE" or new == "DIALOGRESULT") then
		if phase == 1 then
			if progress == 6 and (not enemies[1]["Disculpado2"] or (enemies[1]["Disculpado2"] and enemies[1]["Disculpado2"] ~= 0)) then
				nextwaves = {"Overworld/Flee"}
				State("DEFENDING")
			elseif not SelectedFlee then
				nextwaves = {"Flee"}
				State("DEFENDING")
			else
				if GetAlMightyGlobal("Idioma") == "Spanish" then
					BattleDialog({"[effect:none]Papyrus no te dejará escapar."})
				else
					BattleDialog({"[effect:none]Papyrus won't let you run away."})
				end
			end
			SelectedFlee = true
		elseif phase == 4 then
			if not SelectedFlee2 then
				nextwaves = {"Flee"}
				State("DEFENDING")
			else
				if GetAlMightyGlobal("Idioma") == "Spanish" then
					BattleDialog({"[effect:none]Papyrus no te dejará escapar."})
				else
					BattleDialog({"[effect:none]Papyrus won't let you run away."})
				end
			end
			SelectedFlee2 = true
		else
			if phase == 3 and progress == 0 and not (FUN[1] == "Rare" and FUN[2] == 3) then
				Audio["menuconfirm"] = "st"
			end
			nextwaves = {"Flee"}
			State("DEFENDING")
		end
	elseif new == "ENEMYDIALOGUE" and phase == 4 and Bubbles[1] then
		Bubble("", "", 0, 0, 0, 0, 1)
	elseif new == "ACTIONSELECT" and old == "DEFENDING" and phase == 4 and not moved then
		SetAction("ACT")
		moved = true
	end
	if new == "MERCYMENU" and GetAlMightyGlobal("Idioma") == "Spanish" then
		Perdonar = CreateSprite("Specials/Spare Spanish","Top")
		Perdonar.MoveTo(146, 189)
		if enemies[1]["canspare"] == true then
			Perdonar.color = {1, 1, 0}
		end
		if flee == true then
			Huir = CreateSprite("Specials/Huir","Top")
			Huir.MoveTo(139, 163)
		end
	elseif old == "MERCYMENU" and Perdonar then
		Perdonar.Remove()
		if Huir then
			Huir.Remove()
		end
		Perdonar = nil
		Huir = nil
	end
	if old == "DIALOGRESULT" then
		Inventory.SetInventory(Items)
	end
	UpdateStatesUI(new, old)
end

function EnemyDialogueStarting()
	if GameOver then
		if GetAlMightyGlobal("Idioma") == "Spanish" then
			enemies[1].SetVar("currentdialogue", {"[font:papyrus][voice:papyrus][effect:none]LO SIENTO HUMANO..."})
		else
			enemies[1].SetVar("currentdialogue", {"[font:papyrus][voice:papyrus][effect:none]I'M SORRY HUMAN..."})
		end
	elseif phase == 1 then
		if progress < 6 and (Alternative < 1 or Alternative > 2) then
			progress = progress + 1
		end
		if progress == 1 then
			if GetAlMightyGlobal("Idioma") == "Spanish" then
				enemies[1].SetVar("currentdialogue", {"[noskip][font:papyrus][voice:papyrus][effect:none]DEJAME SABER\nSI ESTO DUELE."})
			else
				enemies[1].SetVar("currentdialogue", {"[noskip][font:papyrus][voice:papyrus][effect:none]LET ME KNOW\nIF THIS HURTS."})
			end
		elseif progress >= 2 and progress <= 6 and Spared and not Perdonando then
			if GetAlMightyGlobal("Idioma") == "Spanish" then
				enemies[1].SetVar("currentdialogue", {"[noskip][font:papyrus][voice:papyrus][effect:none]ESTO ME DUELE\nMÁS DE LO QUE\nTE DUELE A TI."})
			else
				enemies[1].SetVar("currentdialogue", {"[noskip][font:papyrus][voice:papyrus][effect:none]THIS HURTS ME\nMORE THAN IT\nHURTS YOU."})
			end
			Perdonando = true
		end
		if progress == 6 then
			if Ask and Ask == 2 then
				if GetAlMightyGlobal("Idioma") == "Spanish" then
					enemies[1].SetVar("currentdialogue", {"[noskip][font:papyrus][voice:papyrus][effect:none]OH[w:10]\n[func:Head,Okay...]ENTIENDO..."})
				else
					enemies[1].SetVar("currentdialogue", {"[noskip][font:papyrus][voice:papyrus][effect:none]OH[w:10]\n[func:Head,Okay...]I UNDERSTAND..."})
				end
				Ask = 4
			elseif Ask and Ask == 3 then
				if GetAlMightyGlobal("Idioma") == "Spanish" then
					enemies[1].SetVar("currentdialogue", {"[noskip][font:papyrus][voice:papyrus][effect:none][func:Head,Nyehehehe]GRACIAS[w:10]\nNYEHEHEHE..."})
				else
					enemies[1].SetVar("currentdialogue", {"[noskip][font:papyrus][voice:papyrus][effect:none][func:Head,Nyehehehe]THANKS[w:10]\nNYEHEHEHE..."})
				end
				Ask = 4
			end
			if Ask and Ask == 4 and string.sub(GetAlMightyGlobal("Archivimentazo"), 13, 13) == "0" then
				SetAlMightyGlobal("Archivimentazo", string.sub(GetAlMightyGlobal("Archivimentazo"), 1, 12).."1"..string.sub(GetAlMightyGlobal("Archivimentazo"), 14))
				LogroDesbloqueado = {Timer = 0, Icon = 13}
			end
			enemies[1].SetVar("canspare", true)
			if GetAlMightyGlobal("Idioma") == "Spanish" then
				enemies[1]["commands"][4] = "Consolar"
			else
				enemies[1]["commands"][4] = "Console"
			end
		end
	elseif phase == 2 or phase == 3 then
		progress = progress + 1
		if progress == 1 then
			Player.sprite.alpha = 0
		end
	end
end

function EnemyDialogueEnding()
	if GameOver then
		nextwaves = {"Sorry Human"}
	elseif phase == -1 then
		nextwaves = {"Spare"}
	elseif phase == 1 then
		if Alternative == 1 then
			nextwaves = {"Egg "..math.random(3)}
		else
			if progress <= 5 then
				SetHead("Believe")
			end
			if not Done then
				if Ask and Ask == 0 then
					nextwaves = {"Answer"}
					Ask = 1
				else
					nextwaves = {phase1[math.min(progress, 7)]}
				end
				if progress == 6 then
					phase1[6] = "Spare"
				elseif progress == 7 and enemies[1].GetVar("Disculpado2") and enemies[1].GetVar("Disculpado2") == 0 then
					nextwaves = {"Betrayal"}
				end
			else
				nextwaves = {"Overworld/Pacifist"}
			end
		end
	elseif phase == 2 then
		nextwaves = {phase2[progress]}
	elseif phase == 3 then
		if progress == 2 and FUN[1] == "Rare" and FUN[2] == 2 and enemies[2]["Hitted"] then
			nextwaves = {"Sans Dying"}
		else
			nextwaves = {phase3[progress]}
		end
	elseif phase == 4 then
		if Scared == 6 and string.sub(GetAlMightyGlobal("Archivimentazo"), 11, 11) == "0" then
			SetAlMightyGlobal("Archivimentazo", string.sub(GetAlMightyGlobal("Archivimentazo"), 1, 10).."1"..string.sub(GetAlMightyGlobal("Archivimentazo"), 12))
			LogroDesbloqueado = {Timer = 0, Icon = 11}
		end
		if not Bad and not Done then
			nextwaves = {"Spare"}
		elseif Bad then
			nextwaves = {"Die"}
		elseif Done then
			nextwaves = {"Overworld/Pacifist"}
		end
	end
end

function DefenseEnding()
	if GameOver then
		State("ENEMYDIALOGUE")
	elseif phase == -1 then
		if GetAlMightyGlobal("Idioma") == "Spanish" then
			encountertext = "Dónde consiguió Papyrus\runa silla de ruedas?!"
		else
			encountertext = "Where did Papyrus get a\rwheelchair?!"
		end
	elseif phase == 1 then
		if SuperCry then
			nextwaves = {"Box"}
			State("DEFENDING")
			SuperCry = nil
		end
		if Alternative == 1 then
			if not DialogEgg then
				if GetAlMightyGlobal("Idioma") == "Spanish" then
					encountertext = "Te enfrentas a un Egg Dog."
				else
					encountertext = "You confront an Egg Dog."
				end
				DialogEgg = true
			else
				local randomizador = math.random(3)
				if randomizador == 1 then
					if GetAlMightyGlobal("Idioma") == "Spanish" then
						encountertext = "Esto no se ve como el mejor uso\rde tu tiempo."
					else
						encountertext = "This doesn't seem like the best\ruse of your time."
					end
				elseif randomizador == 2 then
					if GetAlMightyGlobal("Idioma") == "Spanish" then
						encountertext = "Huele a caninos y omelettes."
					else
						encountertext = "Smells like cannine and\romelettes."
					end
				else
					if GetAlMightyGlobal("Idioma") == "Spanish" then
						encountertext = "Egg Dog salta emocionado."
					else
						encountertext = "Egg Dog jumps around excitedly."
					end
				end
			end
		else
			if progress == 0 then
				if GetAlMightyGlobal("Idioma") == "Spanish" then
					encountertext = "Papyrus ya no cree en ti..."
				else
					encountertext = "Papyrus no longer believes in\ryou..."
				end
			elseif progress == 1 then
				if GetAlMightyGlobal("Idioma") == "Spanish" then
					encountertext = "Papyrus te mira con una\rexpresión de disculpa."
				else
					encountertext = "Papyrus glares at you with\ran apologetic expression."
				end
			elseif progress == 2 then
				if GetAlMightyGlobal("Idioma") == "Spanish" then
					encountertext = "Te haz metido en una situación\rmuy incómoda."
				else
					encountertext = "You've gotten yourself into a\rvery uncomfortable situation."
				end
			elseif progress == 3 then
				if GetAlMightyGlobal("Idioma") == "Spanish" then
					encountertext = "Parece molesti."
				else
					encountertext = "He seems upsetti."
				end
			elseif progress == 4 then
				if GetAlMightyGlobal("Idioma") == "Spanish" then
					encountertext = "Papyrus traiciona sus verdaderos\rcolores."
				else
					encountertext = "Papyrus betrays his true colors."
				end
			elseif progress == 5 then
				if GetAlMightyGlobal("Idioma") == "Spanish" then
					encountertext = "No molestes al esqueleto."
				else
					encountertext = "Don't noogie the skeleton."
				end
			elseif progress == 6 then
				if enemies[1].GetVar("Disculpado2") and enemies[1].GetVar("Disculpado2") == 0 then
					if GetAlMightyGlobal("Idioma") == "Spanish" then
						encountertext = "[color:ff0000][voice:chara]Papyrus está distraído =)"
					else
						encountertext = "[color:ff0000][voice:chara]Papyrus is distracted =)"
					end
				else
					if GetAlMightyGlobal("Idioma") == "Spanish" then
						encountertext = "Acaba con esto."
					else
						encountertext = "Get it over with."
					end
				end
			elseif progress == 7 or progress == 10 then
				if GetAlMightyGlobal("Idioma") == "Spanish" then
					encountertext = "Acaba con esto."
				else
					encountertext = "Get it over with."
				end
			elseif progress == 9 then
				if GetAlMightyGlobal("Idioma") == "Spanish" then
					encountertext = "Haz que te lasitme."
				else
					encountertext = "Make him hurt you."
				end
			end
		end
	elseif phase == 2 then
		if progress == 1 then
			enemies[1].Call("SetDamageUIOffset", {0, 600})
			enemies[1].SetVar("canspare", false)
			if FUN[1] == "Epic" and FUN[2] == 2 then
				if GetAlMightyGlobal("Idioma") == "Spanish" then
					encountertext = "De dónde vino ese Espagueti?!"
				else
					encountertext = "Where did that Spaghetti come\rfrom?!"
				end
			else
				if GetAlMightyGlobal("Idioma") == "Spanish" then
					encountertext = "Parece que lo has hecho enojar."
				else
					encountertext = "Looks like you've made him angry."
				end
			end
		elseif progress == 3 then
			Backup = Items
			Items = {}
			for i=1,math.max(#Backup, 4) do
				if GetAlMightyGlobal("Idioma") == "Spanish" then
					table.insert(Items, "Espagueti")
				else
					table.insert(Items, "Spaghetti")
				end
			end
			Backup = nil
			Inventory.SetInventory(Items)
			if GetAlMightyGlobal("Idioma") == "Spanish" then
				encountertext = "Sans hubiera encontrado esto\rhúmeroso."
			else
				encountertext = "Sans would have found this\rhumerus."
			end
		end
	elseif phase == 3 then
		if progress == 0 then
			Player.SetAttackAnim({"UI/Battle/spr_slice_o_0","UI/Battle/spr_slice_o_1","UI/Battle/spr_slice_o_2","UI/Battle/spr_slice_o_3","UI/Battle/spr_slice_o_4","UI/Battle/spr_slice_o_5"}, 0.1)
			if GetAlMightyGlobal("Idioma") == "Spanish" then
				encountertext = "Los buenos recuerdos se\rdesvanecen..."
			else
				encountertext = "The good memories are fading\raway..."
			end
		elseif progress == 1 then
			enemies[1]["monstersprite"].x = -90
			enemies[2].Call("SetActive", true)
			if GetAlMightyGlobal("Idioma") == "Spanish" then
				encountertext = "A pesar de todo[w:5], sientes más\rpecados."
			else
				encountertext = "Yet[w:5], more sins are felt."
			end
		elseif progress == 2 then
			enemies[1]["monstersprite"].x = 0
			enemies[3].Call("SetActive", true)
			enemies[1].Call("SetActive", false)
			enemies[2].Call("SetActive", false)
			if GetAlMightyGlobal("Idioma") == "Spanish" then
				encountertext = "No odias cuando el pescado es\rservido con huesos?"
			else
				encountertext = "Don't you just hate it when fish\ris served with bones?"
			end
		end
	elseif phase == 4 then
		enemies[1].Call("SetActive", true)
		enemies[2].Call("SetActive", false)
		enemies[3].Call("SetActive", false)
		if not SkipBoxDialog then
			encountertext = "..."
		else
			if GetAlMightyGlobal("Idioma") == "Spanish" then
				encountertext = "Realmente pensante que te\rmataría justo al final?![w:10]\nCon amor[w:10], Cezar Andrade."
			else
				encountertext = "Did you really think I would\rkill you right at the end?![w:10]\nWith love[w:10], Cezar Andrade."
			end
		end
		SkipBoxDialog = nil
		enemies[1]["canspare"] = true
	end
	Player.sprite.alpha = 1
end

function HandleSpare()
	if phase == -1 then
		if GetAlMightyGlobal("Idioma") == "Spanish" then
			BattleDialog({"[effect:none][color:ff0000][voice:chara]QUE ESTAS HACIENDO?![w:10]\nSOLO MÁTALO YA."})
		else
			BattleDialog({"[effect:none][color:ff0000][voice:chara]WHAT ARE YOU DOING?![w:10]\nJUST KILL HIM ALREADY."})
		end
		enemies[1].SetVar("currentdialogue", {"[font:papyrus][voice:papyrus][effect:none]???"})
	elseif phase == 1 and Alternative ~= 1 then
		if progress >= 1 and progress <= 5 then
			Spared = true
		elseif progress == 6 and (not enemies[1]["Disculpado2"] or (enemies[1]["Disculpado2"] and enemies[1]["Disculpado2"] ~= 0)) then
			if GetAlMightyGlobal("Idioma") == "Spanish" then
				enemies[1].SetVar("currentdialogue", {"[noskip][font:papyrus][voice:papyrus][effect:none][func:Arms, 20][func:Head, What]ME ESTAS\n[color:f2c900]PERDONANDO[color:000000]?",
								  "[noskip][font:papyrus][voice:papyrus][effect:none][func:Arms, 0][w:16][func:Arms, -140][func:Head, Finally!][func:Song][func:Jaw, 22]WOWIE!",
								  "[noskip][font:papyrus][voice:papyrus][effect:none][func:Head, Wait...][func:Jaw, 20]ESPERA,[w:10] ES ESTO\nUN TRUCO...?",
								  "[noskip][font:papyrus][voice:papyrus][effect:none][func:Head, Sorry]DISCULPA,[w:10]\nES SOLO QUE...",
								  "[noskip][font:papyrus][voice:papyrus][effect:none][func:Head, Nyehehehe][func:Jaw, 22]NO ESTABA\nESPERANDO ESTO!",
								  "[noskip][font:papyrus][voice:papyrus][effect:none][func:Head, Sorry][func: Jaw, 20]PENSÉ QUE IBAS\nA ACTUAR\nINCORRECTAMENTE.",
								  "[noskip][font:papyrus][voice:papyrus][effect:none][func:Head, Finally!][func: Jaw, 22]PERO HICISTE LO\nCORRECTO!!"})
			else
				enemies[1].SetVar("currentdialogue", {"[noskip][font:papyrus][voice:papyrus][effect:none][func:Arms, 20][func:Head, What]YOU'RE [color:f2c900]SPARING[color:000000]\nME?",
								  "[noskip][font:papyrus][voice:papyrus][effect:none][func:Arms, 0][w:16][func:Arms, -140][func:Head, Finally!][func:Song][func:Jaw, 22]WOWIE!",
								  "[noskip][font:papyrus][voice:papyrus][effect:none][func:Head, Wait...][func:Jaw, 20]WAIT,[w:10] IS THIS A\nTRICK...?",
								  "[noskip][font:papyrus][voice:papyrus][effect:none][func:Head, Sorry]EXCUSE ME,[w:10]\nIT'S JUST...",
								  "[noskip][font:papyrus][voice:papyrus][effect:none][func:Head, Nyehehehe][func:Jaw, 22]I WASN'T\nEXPECTING THIS!",
								  "[noskip][font:papyrus][voice:papyrus][effect:none][func:Head, Sorry][func: Jaw, 20]I THOUGHT YOU\nWERE GOING TO\nACT INCORRECTLY.",
								  "[noskip][font:papyrus][voice:papyrus][effect:none][func:Head, Finally!][func: Jaw, 22]BUT YOU DID THE\nRIGHT THING!!"})
			end
			GameMusic = "Fade"
			Done = true
		elseif progress == 6 and enemies[1]["Disculpado2"] and enemies[1]["Disculpado2"] == 0 then
			if GetAlMightyGlobal("Idioma") == "Spanish" then
				enemies[1].SetVar("currentdialogue", {"[noskip][font:papyrus][voice:papyrus][effect:none][func:Head, Disappointed]ME ESTAS\n[color:f2c900]PERDONANDO[color:000000]?",
								  "[noskip][font:papyrus][voice:papyrus][effect:none][func:Head, Finally!][func:Jaw, 22]WOWIE!",
								  "[noskip][font:papyrus][voice:papyrus][effect:none][func:Head, Wait...][func:Jaw, 20]ESPERA,[w:10] ES ESTO\nUN TRUCO...?",
								  "[noskip][font:papyrus][voice:papyrus][effect:none][func:Head, Sorry]DISCULPA,[w:10]\nES SOLO QUE...",
								  "[noskip][font:papyrus][voice:papyrus][effect:none][func:Head, Nyehehehe][func:Jaw, 22]NO ESTABA\nESPERANDO ESTO!",
								  "[noskip][font:papyrus][voice:papyrus][effect:none][func:Head, Sorry][func: Jaw, 20]PENSÉ QUE IBAS\nA ACTUAR\nINCORRECTAMENTE.",
								  "[noskip][font:papyrus][voice:papyrus][effect:none][func:Head, Finally!][func: Jaw, 22]PERO HICISTE LO\nCORRECTO!!"})
			else
				enemies[1].SetVar("currentdialogue", {"[noskip][font:papyrus][voice:papyrus][effect:none][func:Head, Disappointed]YOU'RE [color:f2c900]SPARING[color:000000]\nME?",
								  "[noskip][font:papyrus][voice:papyrus][effect:none][func:Head, Finally!][func:Jaw, 22]WOWIE!",
								  "[noskip][font:papyrus][voice:papyrus][effect:none][func:Head, Wait...][func:Jaw, 20]WAIT,[w:10] IS THIS A\nTRICK...?",
								  "[noskip][font:papyrus][voice:papyrus][effect:none][func:Head, Sorry]EXCUSE ME,[w:10]\nIT'S JUST...",
								  "[noskip][font:papyrus][voice:papyrus][effect:none][func:Head, Nyehehehe][func:Jaw, 22]I WASN'T\nEXPECTING THIS!",
								  "[noskip][font:papyrus][voice:papyrus][effect:none][func:Head, Sorry][func: Jaw, 20]I THOUGHT YOU\nWERE GOING TO\nACT INCORRECTLY.",
								  "[noskip][font:papyrus][voice:papyrus][effect:none][func:Head, Finally!][func: Jaw, 22]BUT YOU DID THE\nRIGHT THING!!"})
			end
			GameMusic = "NYEH!"
			Volumen = 1
			Done = true
		elseif progress >= 7 then
			Legs.Set("Papyrus/Legs/Front")
			Body.MoveTo(0, 72)
			Head.MoveTo(4, 62)
			Jaw.MoveTo(Head.x, Head.y - 20)
			Animation = "None"
			fadeGlow = true
			if GetAlMightyGlobal("Idioma") == "Spanish" then
				enemies[1].SetVar("currentdialogue", {"[noskip][font:papyrus][voice:papyrus][effect:none][func:Head, Forgiving]ME ESTAS\n[color:f2c900]PERDONANDO[color:000000]?",
								  "[noskip][font:papyrus][voice:papyrus][effect:none][func:Head, Finally!][func:Jaw, 22]WOWIE!",
								  "[noskip][font:papyrus][voice:papyrus][effect:none][func:Head, Wait...][func:Jaw, 20]ESPERA,[w:10] ES ESTO\nUN TRUCO...?",
								  "[noskip][font:papyrus][voice:papyrus][effect:none][func:Head, Sorry]DISCULPA,[w:10]\nES SOLO QUE...",
								  "[noskip][font:papyrus][voice:papyrus][effect:none][func:Head, Nyehehehe][func:Jaw, 22]NO ESTABA\nESPERANDO ESTO!",
								  "[noskip][font:papyrus][voice:papyrus][effect:none][func:Head, Sorry][func: Jaw, 20]PENSÉ QUE IBAS\nA ACTUAR\nINCORRECTAMENTE.",
								  "[noskip][font:papyrus][voice:papyrus][effect:none][func:Head, Finally!][func: Jaw, 22]PERO HICISTE LO\nCORRECTO!!"})
			else
				enemies[1].SetVar("currentdialogue", {"[noskip][font:papyrus][voice:papyrus][effect:none][func:Head, Forgiving]YOU'RE [color:f2c900]SPARING[color:000000]\nME?",
								  "[noskip][font:papyrus][voice:papyrus][effect:none][func:Head, Finally!][func:Jaw, 22]WOWIE!",
								  "[noskip][font:papyrus][voice:papyrus][effect:none][func:Head, Wait...][func:Jaw, 20]WAIT,[w:10] IS THIS A\nTRICK...?",
								  "[noskip][font:papyrus][voice:papyrus][effect:none][func:Head, Sorry]EXCUSE ME,[w:10]\nIT'S JUST...",
								  "[noskip][font:papyrus][voice:papyrus][effect:none][func:Head, Nyehehehe][func:Jaw, 22]I WASN'T\nEXPECTING THIS!",
								  "[noskip][font:papyrus][voice:papyrus][effect:none][func:Head, Sorry][func: Jaw, 20]I THOUGHT YOU\nWERE GOING TO\nACT INCORRECTLY.",
								  "[noskip][font:papyrus][voice:papyrus][effect:none][func:Head, Finally!][func: Jaw, 22]BUT YOU DID THE\nRIGHT THING!!"})
			end
			GameMusic = "NYEH!"
			Volumen = 1
			Done = true
		end
	elseif phase == 3 then
		StatusPhase3[progress + 1] = "Spare"
		if progress == 2 then
			moved = true
		end
	elseif phase == 4 then
		if GetAlMightyGlobal("Idioma") == "Spanish" then
			enemies[1].SetVar("currentdialogue", {"[noskip][font:papyrus][voice:papyrus][effect:none][func:Head, huh]. . .?",
							  "[noskip][font:papyrus][voice:papyrus][effect:none]REALMENTE\nME ESTAS\n[color:f2c900]PERDONANDO[color:000000]?!",
							  "[noskip][font:papyrus][voice:papyrus][effect:none][func:Head, Thinking]ESO ES...",
							  "[noskip][font:papyrus][voice:papyrus][effect:none][func:Head, Well]GENIAL[w:10][func:Head, Thinking], PERO...",
							  "[noskip][font:papyrus][voice:papyrus][effect:none][func:Head, nyeh...]ES UN POCO\nTARDE PARA\nESO...",
							  "[noskip][font:papyrus][voice:papyrus][effect:none][func:SpecialHead]...",
							  "[noskip][font:papyrus][voice:papyrus][effect:none][func:Head, HEY!][func:Music]PERO HEY![w:10] NO\nTODO ESTA\nPERDIDO AUN!",
							  "[noskip][font:papyrus][voice:papyrus][effect:none][func:Head, Look!]SOLO MIRATE![w:10]\nHICISTE LO\nCORRECTO!",
							  "[noskip][font:papyrus][voice:papyrus][effect:none][func:Head, YES!]SOLAMENTE\nNECESITABAS\nEL APOYO DE MI[w:10][func:Head, NYEH HEH],\nEL GRAN PAPYRUS!"})
		else
			enemies[1].SetVar("currentdialogue", {"[noskip][font:papyrus][voice:papyrus][effect:none][func:Head, huh]. . .?",
							  "[noskip][font:papyrus][voice:papyrus][effect:none]ARE YOU REALLY\n[color:f2c900]SPARING[color:000000] ME?!",
							  "[noskip][font:papyrus][voice:papyrus][effect:none][func:Head, Thinking]THAT IS...",
							  "[noskip][font:papyrus][voice:papyrus][effect:none][func:Head, Well]GREAT[w:10][func:Head, Thinking], BUT...",
							  "[noskip][font:papyrus][voice:papyrus][effect:none][func:Head, nyeh...]IT'S A BIT LATE\nFOR THAT NOW...",
							  "[noskip][font:papyrus][voice:papyrus][effect:none][func:SpecialHead]...",
							  "[noskip][font:papyrus][voice:papyrus][effect:none][func:Head, HEY!][func:Music]BUT HEY![w:10] NOT ALL\nIS LOST YET!",
							  "[noskip][font:papyrus][voice:papyrus][effect:none][func:Head, Look!]JUST LOOK AT\nYOURSELF![w:10]\nYOU DID THE RIGHT\nTHING!",
							  "[noskip][font:papyrus][voice:papyrus][effect:none][func:Head, YES!]YOU ONLY NEEDED\nTHE SUPPORT OF\nME[w:10][func:Head, NYEH HEH], THE GREAT\nPAPYRUS!"})
		end
		Done = true
	end
	if phase ~= -1 then
		State("ENEMYDIALOGUE")
	end
end

function HandleItem(ID)
	if phase == -1 then
		if GetAlMightyGlobal("Idioma") == "Spanish" then
			BattleDialog({"[effect:none][color:ff0000][voice:chara]No desperdicies tus Objetos."})
		else
			BattleDialog({"[effect:none][color:ff0000][voice:chara]Don't waste your Items."})
		end
	else
		if ID == "PIE" then
			if phase == 1 then
				if progress <= 5 and Alternative ~= 1 then
					BattleDialog({"[effect:none]You ate the Butterscotch Pie[w:10]\n"..MessageHeal(200),"Papyrus also found some food.[w:10]\nYou both share a nice meal."})
				else
					BattleDialog({"[effect:none]You ate the Butterscotch Pie[w:10]\n"..MessageHeal(200)})
				end
				Player.Heal(200)
			elseif phase == 2 then
				BattleDialog({"[noskip][effect:none]You ate the[func:SpawnText,Butterscotch Pie]"})
			end
			for i=1,#Items do
				if Items[i] == "Pie" then
					table.remove(Items, i)
					break
				end
			end
			if Alternative ~= 1 then
				NotUsedItems = nil
			end
		elseif ID == "PAY" then
			if phase == 1 then
				if progress <= 5 and Alternative ~= 1 then
					BattleDialog({"[effect:none]Te comiste el Pay de Caramelo[w:10]\n"..MessageHeal(200),"Papyrus tambien encontro algo\rde comida.[w:10]\nAmbos comparten una buena comida."})
				else
					BattleDialog({"[effect:none]Te comiste el Pay de Caramelo[w:10]\n"..MessageHeal(200)})
				end
				Player.Heal(200)
			elseif phase == 2 then
				BattleDialog({"[noskip][effect:none]Te comiste[func:SpawnText,Pay de Caramelo]"})
			end
			for i=1,#Items do
				if Items[i] == "Pay" then
					table.remove(Items, i)
					break
				end
			end
			if Alternative ~= 1 then
				NotUsedItems = nil
			end
		elseif ID == "SNOWPIECE" then
			if phase == 1 then
				if progress <= 5 and Alternative ~= 1 then
					BattleDialog({"[effect:none]You ate the Snowman Piece.[w:10]\n"..MessageHeal(45),"Papyrus also found some food.[w:10]\nYou both share a nice meal."})
				else
					BattleDialog({"[effect:none]You ate the Snowman Piece.[w:10]\n"..MessageHeal(45)})
				end
				Player.Heal(45)
			elseif phase == 2 then
				BattleDialog({"[noskip][effect:none]You ate the[func:SpawnText,Snowman Piece]"})
			end
			for i=1,#Items do
				if Items[i] == "SnowPiece" then
					table.remove(Items, i)
					break
				end
			end
			if Alternative ~= 1 then
				NotUsedItems = nil
			end
		elseif ID == "P. NIEVE" then
			if phase == 1 then
				if progress <= 5 and Alternative ~= 1 then
					BattleDialog({"[effect:none]Te comiste el Pedazo de Nieve[w:10]\n"..MessageHeal(45),"Papyrus tambien encontro algo\rde comida.[w:10]\nAmbos comparten una buena comida."})
				else
					BattleDialog({"[effect:none]Te comiste el Pedazo de Nieve[w:10]\n"..MessageHeal(45)})
				end
				Player.Heal(45)
			elseif phase == 2 then
				BattleDialog({"[noskip][effect:none]Te comiste[func:SpawnText,Pedazo de Nieve]"})
			end
			for i=1,#Items do
				if Items[i] == "P. Nieve" then
					table.remove(Items, i)
					break
				end
			end
			if Alternative ~= 1 then
				NotUsedItems = nil
			end
		elseif ID == "L. HERO" then
			if phase == 1 then
				if progress <= 5 and Alternative ~= 1 then
					BattleDialog({"[effect:none]You ate the Legendary Hero.[w:10]\nYour ATTACK increased by 4![w:10]\n"..MessageHeal(40),"Papyrus also found some food.[w:10]\nYou both share a nice meal."})
				else
					BattleDialog({"[effect:none]You ate the Legendary Hero.[w:10]\nYour ATTACK increased by 4![w:10]\n"..MessageHeal(40)})
					if Alternative == 1 then
						enemies[4]["def"] = enemies[4]["def"] - 40
					end
				end
				Player.Heal(40)
			elseif phase == 2 then
				BattleDialog({"[noskip][effect:none]You ate the[func:SpawnText,Legendary Hero]"})
			end
			for i=1,#Items do
				if Items[i] == "L. Hero" then
					table.remove(Items, i)
					break
				end
			end
			if Alternative ~= 1 then
				NotUsedItems = nil
			end
		elseif ID == "HÉROE L." then
			if phase == 1 then
				if progress <= 5 and Alternative ~= 1 then
					BattleDialog({"[effect:none]Te comiste el Héroe Legendario[w:10]\nTu ATAQUE aumentó por 4![w:10]\n"..MessageHeal(40),"Papyrus tambien encontro algo\rde comida.[w:10]\nAmbos comparten una buena comida."})
				else
					BattleDialog({"[effect:none]Te comiste el Héroe Legendario[w:10]\nTu ATAQUE aumentó por 4![w:10]\n"..MessageHeal(40)})
					if Alternative == 1 then
						enemies[4]["def"] = enemies[4]["def"] - 40
					end
				end
				Player.Heal(40)
			elseif phase == 2 then
				BattleDialog({"[noskip][effect:none]Te comiste[func:SpawnText,Héroe Legendario]"})
			end
			for i=1,#Items do
				if Items[i] == "Héroe L." then
					table.remove(Items, i)
					break
				end
			end
			if Alternative ~= 1 then
				NotUsedItems = nil
			end
		elseif ID == "C. SPAGHETTI" then
			if phase == 1 then
				local randomizador = math.random(40, 70)
				if progress <= 5 and Alternative ~= 1 then
					SetHead("Blocking")
					BattleDialog({"[effect:none]You ate the Cold Spaghetti.[w:10]\nPapyrus looks at you sadly.[w:10]\n"..MessageHeal(randomizador),"Even though the spaghetti is\rcold it tastes very good."})
					enemies[1].SetVar("currentdialogue", {"[font:papyrus][voice:papyrus][effect:none][color:FF0000]BONE[color:000000] APPETIT[w:10]\nNYHEHEHE..."})
				else
					if Alternative ~= 1 then
						if progress == 6 and enemies[1].GetVar("Disculpado2") and enemies[1].GetVar("Disculpado2") == 0 and not Ask then
							SetHead("Disappointed")
							enemies[1].SetVar("currentdialogue", {"[noskip][font:papyrus][voice:papyrus][effect:none]DID YOU LIKE IT?"})
							Ask = 0
						elseif progress > 6 then
							SetHead("Blocking")
						end
					end
					BattleDialog({"[effect:none]You ate the Cold Spaghetti.[w:10]\n"..MessageHeal(randomizador),"Even though the spaghetti is\rcold it tastes very good."})
				end
				Player.Heal(randomizador)
			elseif phase == 2 then
				BattleDialog({"[noskip][effect:none]You ate the[func:SpawnText,Cold Spaghetti]"})
			end
			for i=1,#Items do
				if Items[i] == "C. Spaghetti" then
					table.remove(Items, i)
					break
				end
			end
			if Alternative ~= 1 then
				NotUsedItems = nil
			end
		elseif ID == "ESPAGUETI F." then
			if phase == 1 then
				local randomizador = math.random(40, 70)
				if progress <= 5 and Alternative ~= 1 then
					SetHead("Blocking")
					BattleDialog({"[effect:none]Te comiste el Espagueti Frío.[w:10]\nPapyrus te mira tristemente.[w:10]\n"..MessageHeal(randomizador),"Aunque el espagueti esta\rfrío sabe muy bien."})
					enemies[1].SetVar("currentdialogue", {"[font:papyrus][voice:papyrus][effect:none][color:FF0000]BONE[color:000000] APETITO[w:10]\nNYHEHEHE..."})
				else
					if Alternative ~= 1 then
						if progress == 6 and enemies[1].GetVar("Disculpado2") and enemies[1].GetVar("Disculpado2") == 0 and not Ask then
							SetHead("Disappointed")
							enemies[1].SetVar("currentdialogue", {"[noskip][font:papyrus][voice:papyrus][effect:none]TE GUSTÓ?"})
							Ask = 0
						elseif progress > 6 then
							SetHead("Blocking")
						end
					end
					BattleDialog({"[effect:none]Te comiste el Espagueti Frío.[w:10]\n"..MessageHeal(randomizador),"Aunque el espagueti esta\rfrío sabe muy bien."})
				end
				Player.Heal(randomizador)
			elseif phase == 2 then
				BattleDialog({"[noskip][effect:none]Te comiste[func:SpawnText,Espagueti Frío]"})
			end
			for i=1,#Items do
				if Items[i] == "Espagueti F." then
					table.remove(Items, i)
					break
				end
			end
			if Alternative ~= 1 then
				NotUsedItems = nil
			end
		elseif ID == "SPAGHETTI" then
			if phase == 2 then
				BattleDialog({"[noskip][effect:none](You take a big bite.)","[noskip][effect:none](Your face reflexively scrunches\rup.)","[noskip][effect:none](It's even worse than last\rtime...)","[func:Recover,"..math.random(15, 45).."]"})
			elseif phase == 3 then
				local randomizador = math.random(30, 75)
				BattleDialog({"You ate the Spaghetti.[w:10]\n"..MessageHeal(randomizador)})
				StatusPhase3[progress + 1] = "Item"
				Player.Heal(randomizador)
			elseif phase == 4 then
				local randomizador = math.random(30, 75)
				BattleDialog({"You ate the Spaghetti.[w:10]\n"..MessageHeal(randomizador)})
				if not SelectedFlee2 and not Scared then
					enemies[1].SetVar("currentdialogue", {"[noskip][font:papyrus][voice:papyrus][effect:none][waitall:5]. . ."})
				elseif not Itemed then
					enemies[1].SetVar("currentdialogue", {"[noskip][font:papyrus][voice:papyrus][effect:none]I CAN MAKE YOU\nMORE IF YOU\n[color:f2c900]SPARE[color:000000] ME...","[noskip][font:papyrus][voice:papyrus][effect:none]PLEASE...[w:10]\nI'M STILL YOUR\nFRIEND..."})
					Itemed = true
				end
				Player.Heal(randomizador)
				moved = true
			end
			for i=1,#Items do
				if Items[i] == "Spaghetti" then
					table.remove(Items, i)
					break
				end
			end
			if Alternative ~= 1 then
				NotUsedItems = nil
			end
		elseif ID == "ESPAGUETI" then
			if phase == 2 then
				BattleDialog({"[noskip][effect:none](Das un gran mordisco.)","[noskip][effect:none](Tu cara reflexivamente se\rarrugó.)","[noskip][effect:none](Es incluso peor que la última\rvez...)","[func:Recover,"..math.random(15, 45).."]"})
			elseif phase == 3 then
				local randomizador = math.random(30, 75)
				BattleDialog({"Te comiste el Espagueti.[w:10]\n"..MessageHeal(randomizador)})
				StatusPhase3[progress + 1] = "Item"
				Player.Heal(randomizador)
			elseif phase == 4 then
				local randomizador = math.random(30, 75)
				BattleDialog({"Te comiste el Espagueti.[w:10]\n"..MessageHeal(randomizador)})
				if not SelectedFlee2 and not Scared then
					enemies[1].SetVar("currentdialogue", {"[noskip][font:papyrus][voice:papyrus][effect:none][waitall:5]. . ."})
				elseif not Itemed then
					enemies[1].SetVar("currentdialogue", {"[noskip][font:papyrus][voice:papyrus][effect:none]PUEDO HACERTE\nMÁS SI ME\n[color:f2c900]PERDONAS[color:000000]...","[noskip][font:papyrus][voice:papyrus][effect:none]POR FAVOR...[w:10]\nSIGO SIENDO TU\nAMIGO..."})
					Itemed = true
				end
				Player.Heal(randomizador)
				moved = true
			end
			for i=1,#Items do
				if Items[i] == "Espagueti" then
					table.remove(Items, i)
					break
				end
			end
			if Alternative ~= 1 then
				NotUsedItems = nil
			end
		end
		if #Items <= 0 then
			if GetAlMightyGlobal("Idioma") == "Spanish" then
				Items = {"[starcolor:7d7d7d][color:7d7d7d]Nada[color:ffffff]"}
			else
				Items = {"[starcolor:7d7d7d][color:7d7d7d]Nothing[color:ffffff]"}
			end
		end
	end
end

function Recover(amount)
	Player.Heal(amount)
	progress = progress + 1
	EnemyDialogueEnding()
	State("DEFENDING")
end

function MessageHeal(cant)
	if (Player.hp + cant >= Player.lv*4 + 16 and (phase < 3 or (phase == 3 and progress <= 0))) or (Player.hp + cant >= 184 and ((phase >= 3 and progress > 0) or phase >= 4)) then
		if GetAlMightyGlobal("Idioma") == "Spanish" then
			return "Tu HP está al maximo!"
		else
			return "Your HP was maxed out!"
		end
	else
		if GetAlMightyGlobal("Idioma") == "Spanish" then
			return "Recuperaste "..cant.." HP!"
		else
			return "You recovered "..cant.." HP!"
		end
	end
end

function MISS()
	Miss = CreateSprite("Specials/MISS","Top")
	Miss.MoveTo(320, 420)
	timerMiss = 0
end

function ContinueMusic()
	if phase == 1 then
		if GameMusic == "Playing" then
			GameMusic = "Volume"
		elseif GameMusic == "Volume" then
			GameMusic = "Cry"
		elseif GameMusic == "Crying" then
			GameMusic = "Believe"
		elseif GameMusic == "Wait" then
			GameMusic = "Stop"
		end
	elseif phase == 2 then
		if GameMusic == "End" then
			GameMusic = "Start"
		elseif GameMusic == "Wait 1" then
			GameMusic = "Continue 1"
		elseif GameMusic == "Wait 2" then
			GameMusic = "Continue 2"
		elseif GameMusic == "Wait 3" and NewAudio.GetPlayTime("Loop") > 6.64 then
			GameMusic = "Continue 3"
		elseif GameMusic == "Wait 4" then
			GameMusic = "Continue 4"
		elseif GameMusic == "Wait 5" then
			GameMusic = "Fade"
		end
	elseif phase == 3 then
		if GameMusic == "End" then
			GameMusic = "Prepare"
		elseif GameMusic == "Wait 1" then
			GameMusic = "Continue 1"
		elseif GameMusic == "Wait 2" then
			GameMusic = "Continue 2"
		elseif GameMusic == "Wait 3" then
			GameMusic = "Continue 3"
		elseif GameMusic == "Wait 4" then
			GameMusic = "Continue 4"
		elseif GameMusic == "Wait 5" then
			GameMusic = "Continue 5"
		end
	end
end

function LoadMusic()
	NewAudio.CreateChannel("One")
	NewAudio.CreateChannel("Loop")
	NewAudio.PlaySound("Loop", "Believe", true, 0)
	NewAudio.PlaySound("Loop", "Bowsy Music Loop", false, 0)
	NewAudio.PlaySound("Loop", "Death Egg Robot", false, 0)
	NewAudio.PlaySound("Loop", "Game Over", true, 0)
	NewAudio.PlaySound("Loop", "Predummy", true, 0)
	NewAudio.PlaySound("Loop", "choice", true, 0)
	NewAudio.PlaySound("Loop", "Chiptune", true, 0)
	NewAudio.PlaySound("Loop", "Snowdin Town Music Box by Shigurizu Chan", true, 0)
	NewAudio.PlaySound("Loop", "Loop Phase 1", true, 0)
	NewAudio.PlaySound("Loop", "Loop 1 Phase 2", true, 0)
	NewAudio.PlaySound("Loop", "Loop 2 Phase 2", true, 0)
	NewAudio.PlaySound("Loop", "Loop 3 Phase 2", true, 0)
	NewAudio.PlaySound("Loop", "Loop 1 Phase 3", true, 0)
	NewAudio.PlaySound("Loop", "Loop 2 Phase 3", true, 0)
	NewAudio.PlaySound("Loop", "Loop 3 Phase 3", true, 0)
	NewAudio.PlaySound("Loop", "Loop 4 Phase 3", true, 0)
	NewAudio.PlaySound("Loop", "Loop 5 Phase 3", true, 0)
	NewAudio.PlaySound("Loop", "Papyrus", true, 0)
	NewAudio.PlaySound("Loop", "Birds", true, 0)
	NewAudio.PlaySound("Loop", "Goodnight", true, 0)
	NewAudio.PlaySound("Loop", "prejoker", true, 0)
	NewAudio.PlaySound("Loop", "Enemy Aproaching", true, 0)
	NewAudio.PlaySound("One", "Ending Phase 1", false, 0)
	NewAudio.PlaySound("One", "Dark Darker Yet Darker Remix", false, 0)
	NewAudio.PlaySound("One", "The World Revolving Metal Cover", false, 0)
	NewAudio.PlaySound("One", "Bowsy Music Intro", false, 0)
	NewAudio.PlaySound("One", "cYsmix - Peer Gynt", false, 0)
	NewAudio.PlaySound("One", "Intro Phase 2", false, 0)
	NewAudio.PlaySound("One", "Intro Death Egg Robot", false, 0)
	NewAudio.PlaySound("One", "Intro 1 Phase 2", false, 0)
	NewAudio.PlaySound("One", "Intro 2 Phase 2", false, 0)
	NewAudio.PlaySound("One", "Intro 3 Phase 2", false, 0)
	NewAudio.PlaySound("One", "Intro 4 Phase 2", false, 0)
	NewAudio.PlaySound("One", "Intro 1 Phase 3", false, 0)
	NewAudio.PlaySound("One", "Intro 2 Phase 3", false, 0)
	NewAudio.PlaySound("One", "Intro 3 Phase 3", false, 0)
	NewAudio.PlaySound("One", "Intro 4 Phase 3", false, 0)
	NewAudio.PlaySound("One", "Intro 5 Phase 3", false, 0)
	NewAudio.PlaySound("One", "Intro 6 Phase 3", false, 0)
	NewAudio.PlaySound("One", "Phase 4", false, 0)
	NewAudio.PlaySound("One", "Intro Phase 1 Short", false, 0)
	NewAudio.PlaySound("One", "Intro Phase 1", false, 0)
	NewAudio.PlaySound("One", "Zef - Tension", false, 0)
	NewAudio.PlaySound("One", "Bonetrousle - Megalovania Piano", false, 0)
	NewAudio.Stop("Loop")
	NewAudio.Stop("One")
end

function LoadSounds()
	NewAudio.CreateChannel("Sounds")
	NewAudio.PlaySound("Sounds", "bark", false, 0)
	NewAudio.PlaySound("Sounds", "begin", false, 0)
	NewAudio.PlaySound("Sounds", "Bomb", false, 0)
	NewAudio.PlaySound("Sounds", "BombExplotion", false, 0)
	NewAudio.PlaySound("Sounds", "BossHit", false, 0)
	NewAudio.PlaySound("Sounds", "bouncePlat", false, 0)
	NewAudio.PlaySound("Sounds", "bouncePlat2", false, 0)
	NewAudio.PlaySound("Sounds", "bounceWall", false, 0)
	NewAudio.PlaySound("Sounds", "bounceWall2", false, 0)
	NewAudio.PlaySound("Sounds", "bowsydead", false, 0)
	NewAudio.PlaySound("Sounds", "bowsypoundhelikoopa", false, 0)
	NewAudio.PlaySound("Sounds", "Buzzsaw", false, 0)
	NewAudio.PlaySound("Sounds", "bye bye", false, 0)
	NewAudio.PlaySound("Sounds", "chaos CHAOS", false, 0)
	NewAudio.PlaySound("Sounds", "checkpoint", false, 0)
	NewAudio.PlaySound("Sounds", "closet impact", false, 0)
	NewAudio.PlaySound("Sounds", "confirm", false, 0)
	NewAudio.PlaySound("Sounds", "Congratulations", false, 0)
	NewAudio.PlaySound("Sounds", "damage", false, 0)
	NewAudio.PlaySound("Sounds", "dead2", false, 0)
	NewAudio.PlaySound("Sounds", "Dead", false, 0)
	NewAudio.PlaySound("Sounds", "DevilsKnife", false, 0)
	NewAudio.PlaySound("Sounds", "ding", false, 0)
	NewAudio.PlaySound("Sounds", "Distorsion", false, 0)
	NewAudio.PlaySound("Sounds", "Drill", false, 0)
	NewAudio.PlaySound("Sounds", "Drop", false, 0)
	NewAudio.PlaySound("Sounds", "dust", false, 0)
	NewAudio.PlaySound("Sounds", "encounter", false, 0)
	NewAudio.PlaySound("Sounds", "error", false, 0)
	NewAudio.PlaySound("Sounds", "explode", false, 0)
	NewAudio.PlaySound("Sounds", "Explosion3", false, 0)
	NewAudio.PlaySound("Sounds", "fallingbomb", false, 0)
	NewAudio.PlaySound("Sounds", "Fireball", false, 0)
	NewAudio.PlaySound("Sounds", "flee", false, 0)
	NewAudio.PlaySound("Sounds", "Game Over Paps", false, 0)
	NewAudio.PlaySound("Sounds", "gasterfire", false, 0)
	NewAudio.PlaySound("Sounds", "gasterintro", false, 0)
	NewAudio.PlaySound("Sounds", "gasterintro2", false, 0)
	NewAudio.PlaySound("Sounds", "gasterintrofast", false, 0)
	NewAudio.PlaySound("Sounds", "gastervibration", false, 0)
	NewAudio.PlaySound("Sounds", "HAHAHAHA", false, 0)
	NewAudio.PlaySound("Sounds", "HappyDamage", false, 0)
	NewAudio.PlaySound("Sounds", "HappyDust", false, 0)
	NewAudio.PlaySound("Sounds", "HappyExplotion", false, 0)
	NewAudio.PlaySound("Sounds", "HappySlice", false, 0)
	NewAudio.PlaySound("Sounds", "healsound", false, 0)
	NewAudio.PlaySound("Sounds", "heavydamage", false, 0)
	NewAudio.PlaySound("Sounds", "hit", false, 0)
	NewAudio.PlaySound("Sounds", "hitBowsy", false, 0)
	NewAudio.PlaySound("Sounds", "hitshells", false, 0)
	NewAudio.PlaySound("Sounds", "hitsound", false, 0)
	NewAudio.PlaySound("Sounds", "HullClose", false, 0)
	NewAudio.PlaySound("Sounds", "hurt", false, 0)
	NewAudio.PlaySound("Sounds", "hurtsound", false, 0)
	NewAudio.PlaySound("Sounds", "I can do anything", false, 0)
	NewAudio.PlaySound("Sounds", "impact", false, 0)
	NewAudio.PlaySound("Sounds", "Impact2", false, 0)
	NewAudio.PlaySound("Sounds", "gasterintro2", false, 0)
	NewAudio.PlaySound("Sounds", "Impact6", false, 0)
	NewAudio.PlaySound("Sounds", "jump", false, 0)
	NewAudio.PlaySound("Sounds", "laugh1", false, 0)
	NewAudio.PlaySound("Sounds", "laugh2", false, 0)
	NewAudio.PlaySound("Sounds", "laugh3", false, 0)
	NewAudio.PlaySound("Sounds", "LedgeBreak", false, 0)
	NewAudio.PlaySound("Sounds", "LedgeBreak2", false, 0)
	NewAudio.PlaySound("Sounds", "logro", false, 0)
	NewAudio.PlaySound("Sounds", "lol You died", false, 0)
	NewAudio.PlaySound("Sounds", "MultiBone", false, 0)
	NewAudio.PlaySound("Sounds", "NEO chaos", false, 0)
	NewAudio.PlaySound("Sounds", "mysterious", false, 0)
	NewAudio.PlaySound("Sounds", "nothing", false, 0)
	NewAudio.PlaySound("Sounds", "OH", false, 0)
	NewAudio.PlaySound("Sounds", "Pon", false, 0)
	NewAudio.PlaySound("Sounds", "pierce", false, 0)
	NewAudio.PlaySound("Sounds", "pip", false, 0)
	NewAudio.PlaySound("Sounds", "poundbigbomb", false, 0)
	NewAudio.PlaySound("Sounds", "poundbomb", false, 0)
	NewAudio.PlaySound("Sounds", "ring", false, 0)
	NewAudio.PlaySound("Sounds", "roughhit", true, 0)
	NewAudio.PlaySound("Sounds", "save", false, 0)
	NewAudio.PlaySound("Sounds", "scream", false, 0)
	NewAudio.PlaySound("Sounds", "shootbomb", true, 0)
	NewAudio.PlaySound("Sounds", "slam", true, 0)
	NewAudio.PlaySound("Sounds", "slice", false, 0)
	NewAudio.PlaySound("Sounds", "sparkle", false, 0)
	NewAudio.PlaySound("Sounds", "sparkleslow", true, 0)
	NewAudio.PlaySound("Sounds", "spawn", false, 0)
	NewAudio.PlaySound("Sounds", "spearswing", false, 0)
	NewAudio.PlaySound("Sounds", "st", false, 0)
	NewAudio.PlaySound("Sounds", "start", false, 0)
	NewAudio.PlaySound("Sounds", "suspenso", true, 0)
	NewAudio.PlaySound("Sounds", "Targeting1", true, 0)
	NewAudio.PlaySound("Sounds", "throw", false, 0)
	NewAudio.PlaySound("Sounds", "throwfire", true, 0)
	NewAudio.PlaySound("Sounds", "throwthings", true, 0)
	NewAudio.PlaySound("Sounds", "toss", true, 0)
	NewAudio.PlaySound("Sounds", "ueeueeueeuee", true, 0)
	NewAudio.PlaySound("Sounds", "uh", true, 0)
	NewAudio.PlaySound("Sounds", "wow", true, 0)
	NewAudio.PlaySound("Sounds", "Voices/asgore", false, 0)
	NewAudio.PlaySound("Sounds", "Voices/chara", false, 0)
	NewAudio.PlaySound("Sounds", "Voices/determined papyrus", false, 0)
	NewAudio.PlaySound("Sounds", "Voices/mad papyrus", false, 0)
	NewAudio.PlaySound("Sounds", "Voices/monster", false, 0)
	NewAudio.PlaySound("Sounds", "Voices/papyrus loud", false, 0)
	NewAudio.PlaySound("Sounds", "Voices/papyrus pitched", false, 0)
	NewAudio.PlaySound("Sounds", "Voices/papyrus", false, 0)
	NewAudio.PlaySound("Sounds", "Voices/sans fast", false, 0)
	NewAudio.PlaySound("Sounds", "Voices/ui", false, 0)
	NewAudio.PlaySound("Sounds", "Voices/undyne", false, 0)
	NewAudio.Stop("Sounds")
	NewAudio.DestroyChannel("Sounds")
end

function Trigger()
	Triggered = true
end